import type { NginxConfig } from '@/types'
import { api } from './api'

export interface NginxConfigInfo {
  name: string;
  content: string;
  file_path: string;
}

export const nginxService = {
  // 获取所有配置列表
  async getConfigs(): Promise<NginxConfigInfo[]> {
    const response = await api.get<{ configs: NginxConfigInfo[] }>('/nginx/configs')
    return response.data.configs
  },

  // 获取主配置文件
  async getMainConfig(): Promise<NginxConfigInfo> {
    const response = await api.get<{ config: NginxConfigInfo }>('/nginx/main-config')
    return response.data.config
  },

  // 测试配置
  async testConfig(): Promise<{ message: string }> {
    const response = await api.post<{ message: string }>('/nginx/test')
    return response.data
  },

  // 重新加载配置
  async reloadConfig(): Promise<{ message: string }> {
    const response = await api.post<{ message: string }>('/nginx/reload')
    return response.data
  }
} 